a=input()
spaces=0
for x in a:
    if x==' ':
        spaces+=1
if spaces!=2:
    print('Wrong input')
    exit()
num1,num2,num3=map(str,a.split())
match(num1):
    case 'zero':
        num1='0'
    case 'one':
        num1='1'
    case 'two':
        num1='2'
    case 'three':
        num1='3'
    case 'four':
        num1='4'
    case 'five':
        num1='5'
    case 'six':
        num1='6'
    case 'seven':
        num1='7'
    case 'eight':
        num1='8'
    case 'nine':
        num1='9'
    case _:
        print('Wrong input')
        exit()
match(num2):
    case 'zero':
        num2='0'
    case 'one':
        num2='1'
    case 'two':
        num2='2'
    case 'three':
        num2='3'
    case 'four':
        num2='4'
    case 'five':
        num2='5'
    case 'six':
        num2='6'
    case 'seven':
        num2='7'
    case 'eight':
        num2='8'
    case 'nine':
        num2='9'
    case _:
        print('Wrong input')
        exit()
match(num3):
    case 'zero':
        num3='0'
    case 'one':
        num3='1'
    case 'two':
        num3='2'
    case 'three':
        num3='3'
    case 'four':
        num3='4'
    case 'five':
        num3='5'
    case 'six':
        num3='6'
    case 'seven':
        num3='7'
    case 'eight':
        num3='8'
    case 'nine':
        num3='9'
    case _:
        print('Wrong input')
        exit()

num=int(num1+num2+num3)
pr=[]
for i in range(num-100,num+100):
    flag=0
    for j in range(2,i):
        if i%j==0:
            flag=1
            break
    if flag==0:
        pr.append(i)
raz=1000
ans=[]
for i in pr:
    if i<num:
        if num-i<raz:
            raz=num-i
    if i>num:
        if i-num<raz:
            raz=num-i
    if i==num:
        raz=0
        ans.append(i)
        break
        

for i in pr:
    if num-i==raz:
        ans.append(i)
    if i-num==raz:
        ans.append(i)
print(min(ans))

